package com.ymatou.startApp;

import java.io.IOException;

import android.os.RemoteException;

import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.ymatou.util.Logger;

@SuppressWarnings("deprecation")
public class NewUserCouponDialogTest extends UiAutomatorTestCase{
	
	private static final String TAG = NewUserCouponDialogTest.class.getSimpleName();
	
	public static void newUserCouponDialog(boolean isClose) throws IOException, 
	UiObjectNotFoundException, RemoteException {
		UiSelector home_coupon_dialog_s = new UiSelector().resourceId("com.ymatou.shop:id/tv_home_coupon_dialog_go");
	    UiObject home_coupon_dialog_o = new UiObject(home_coupon_dialog_s);
	    home_coupon_dialog_o.waitForExists(5000);
	    
	    if (home_coupon_dialog_o.exists()) {
	    	Logger.log(TAG, "存在新人弹出框");
	    	if (isClose) {
	    		Logger.log(TAG, "关闭新人券弹窗");
	    		
	    		UiSelector home_coupon_dialog_cancel_s = new UiSelector().resourceId("com.ymatou.shop:id/tv_home_coupon_dialog_cancel");
	    		UiObject home_coupon_dialog_cancel_o = new UiObject(home_coupon_dialog_cancel_s);
	    		
	    		home_coupon_dialog_cancel_o.click();
	    		Logger.log(TAG, "关闭新人弹窗");
	    	} else {
		    	home_coupon_dialog_o.click();
	    		Logger.log(TAG, "跳转到新人券或者活动页面");
	    		
	    		UiSelector rl_top_back_s = new UiSelector().resourceId("com.ymatou.shop:id/rl_top_back");
	    		UiObject rl_top_back_o = new UiObject(rl_top_back_s);
	    		
	    		rl_top_back_o.click();
	    		Logger.log(TAG, "点击返回跳转到首页");
	    	}
	    }
    }
}
